#include<stdio.h>

#define MAX 100

typedef int Element;
typedef struct MaxHeap
{
    Element* A;
    int size;
} MaxHeap;
inline void swap_int(int* a, int* b);
void swap_int(int* a, int* b)
{
    int tmp = *a;
    *a = *b;*b = tmp;
}

void percolate_down(MaxHeap H, int i)
{
    int value = H.A[i];
    while (2*i+1<=H.size-1)
    {
        int larger = (2*i+2>=H.size || H.A[2*i+1]>=H.A[2*i+2]) ? 2*i+1: 2*i+2;
        if(H.A[larger] > value)
        {
            H.A[i] = H.A[larger];
            i = larger;
        }
        else break;
    }
    H.A[i] = value;
}

void Heapify(MaxHeap H)
{
    for(int i = H.size/2-1; i>=0;--i)
    {
        percolate_down(H,i);
    }
}

void HeapSort(Element* A, int N)
{
    MaxHeap H = {A,N};
    Heapify(H);
    while(H.size>0)
    {
        swap_int(H.A, H.A+H.size-1);
        --H.size;
        percolate_down(H,0);
    }
}

int main(int argc, char const *argv[])
{
    freopen("./algorithm/test.txt","r",stdin);
    int N; scanf("%d",&N);
    int l[MAX]; for(int i=0;i<N;i++) scanf("%d",l+i);

    HeapSort(l,N);
    
    for(int i=0;i<N;++i)
    {
        printf("%d ",l[i]);
    }
    return 0;
}
